/**
 * 核心技术支持
 * IT渠道网 小程序商城
 * 13873174181 微信同号
 */
import {Base} from '../../utils/base.js';

class My extends Base {
    constructor(){
        super();
    }
    /**
     * 获取用户
     */
    getUserInfo(cb, int) {
        var that = this;
        wx.getUserInfo({
            success: function(res) {
                typeof cb == "function" && cb(res.userInfo);
                if (int == 1) {
                    if (that.onPay) {
                        that._updateUserInfo(res.userInfo);
                    } 
                }
            },
            fail: function(res) {
                typeof cb == "function" && cb({
                    avatarUrl: '../../imgs/icon/default.png',
                    nickName: '未授权'
                })
            }
        })
    }
    /**
     * 订单数
     */
    findMyData(callback) {
        var that = this;
        var allParams = {
            url: 'min/user/mydata',
            sCallback: function (data) {
                callback && callback(data);
            }
        }
        this.request(allParams);
    }
    /**
     * 保存用户信息
     */
    _updateUserInfo(res) {
        var allParams = {
            url: '/min/user/update',
            data: res,
            type: 'post',
            sCallback: function(data) {
            }
        }
        this.request(allParams);
    }
}

export {My};